<form action="<?php echo base_url('user/edituser'); ?>" id="edit-form" class="form-horizontal" method="post">
 <div class="content_block col-xs-12 col-sm-12 col-md-12 col-lg-12">
 <legend><b>Edit User&nbsp;&nbsp;(<?php echo $data["username"]?>)</b></legend>
  <fieldset>


  <input type="hidden" name="id" value="<?php echo $data['id']; ?>" />
    <div class="form-group">
      <label class="col-sm-3 control-label" for="first_name">Username</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" value="<?php echo $data["username"]?>" disabled>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-3 control-label" for="Password">Password</label>
      <div class="col-sm-4">
        <input type="password" class="col-sm-4 form-control" name="password" id="password"  data-min-chars="6" value="" >
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="repassword">Password Again</label>
      <div class="col-sm-4">
        <input type="password" class="col-sm-4 form-control" name="repassword" id="repassword"  data-min-chars="6" value="" >
      </div>
    </div>
    <?php

    if(!empty($groups) AND $this->ion_auth->in_group("admin")){ 
    ?>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="group">Group</label>
        <div class="col-sm-4">
          <!-- TODO: change this select to check box for multiple select -->
            <?php
            foreach($groups as $group)  : 
              $isChecked = "";
              foreach ($data['group'] as $key => $value) {
                if($value["id"] == $group["id"]){
                  $isChecked = "checked";
                }
              }
            ?>
            <div class="checkbox">
              <label>
                <input type="checkbox" name="groups[]" value="<?php echo $group['id'];?>" <?php echo $isChecked;?> >  <?php echo $group['name']?>
              </label>
            </div>
           <?php endforeach; ?>
        </div>
      </div>
    <?php } ?>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="first_name">First Name</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" name="first_name" id="first_name"value="<?php echo $data["first_name"]?>">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="last_name">Last Name</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" name="last_name" id="last_name" value="<?php echo $data["last_name"]?>" >
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-3 control-label" for="email">Email</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" data-min-chars="5" data-email name="email" id="email" value="<?php echo $data["email"]?>" >
        <span class="emailalert" style="display:none;">Available</span>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-3 control-label" for="last_name">Facebook</label>
      <div class="col-sm-6">
        <input type="text" class="col-sm-12 form-control required" data-min-chars="5" data-email name="facebook" id="facebook" value="<?php echo $data["facebook"]?>">
        <span class="emailalert" style="display:none;">Available</span>
      </div>
    </div>
    

    <div class="form-group">
      <label class="col-sm-3 control-label" for="last_name">Line</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" data-min-chars="5"  name="line" id="line" value="<?php echo $data["line"]?>" >
        <span class="emailalert" style="display:none;">Available</span>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label">Gender</label>
      <div class="col-sm-4">
          <label class="radio-inline">
            <input type="radio" name="gender" value="m" id="gender[m]" <?php echo $data["gender"] == 'm' ? "checked":""?> >ชาย</label>
          <label class="radio-inline">
            <input type="radio" name="gender" value="f" id="gender[w]" <?php echo $data["gender"] == 'f' ? "checked":""?>>หญิง</label>
        </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="Mobile">Mobile</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" name="mobile" id="mobile" data-int data-max-chars="11"value="<?php echo $data["mobile"]?>">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="Phone">Phone</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" name="phone" id="phone" data-int data-max-chars="10" value="<?php echo $data["phone"]?>" >
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="Address">Address</label>
      <div class="col-sm-4">
        <textarea class="col-sm-4 form-control required" name="address"  rows="3" id="address"><?php echo $data["address"]?></textarea>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="District">District</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" name="district" id="district" value="<?php echo $data["district"]?>">
      </div>
    </div>
     <div class="form-group">
      <label class="col-sm-3 control-label" for="Province">Province</label>
      <div class="col-sm-4">
      <select name="province" id="province" class="col-sm-4 form-control required">
  			<?php
          $provinces = $this->config->item("province");
          foreach ($provinces as $key => $value) {
            if($data["province"] == $key){
              ?>
              <option value="<?php echo $key;?>" selected><?php echo $value;?></option>
              <?php
            }else{
              ?>
              <option value="<?php echo $key;?>"><?php echo $value;?></option>
              <?php
            }
          }
        ?>
		  </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-3 control-label" for="Zipcode">Zip Code</label>
      <div class="col-sm-4">
        <input type="text" class="col-sm-4 form-control required" name="zipcode" id="zipcode" data-int data-max-chars="6"value="<?php echo $data["zipcode"]?>">
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-3 col-sm-9">
        <button type="submit" class="btn btn-primary" id="submit" name="submit" value="submit">ยืนยัน</button>
        <a href="<?php echo base_url();?>" class="btn btn-default">ยกเลิก</a>
      </div>
    </div>


</fieldset>
</div>
</form>

<?php
PageUtil::addVar("stylesheet","<link href=\"".$stylepath."/user.css\" rel=\"stylesheet\">");
PageUtil::addVar("javascript_body","<script type=\"text/javascript\" src=\"".$jspath."/jquery.validate.js\"></script>");
PageUtil::addVar("javascript_body","<script type=\"text/javascript\" src=\"".$jspath."/additional-methods.js\"></script>");
PageUtil::addVar("javascript_body","<script type=\"text/javascript\">
$(function() {
  $.validator.addMethod(
          \"regex\",
          function(value, element, regexp) {
              var re = new RegExp(regexp);
              return this.optional(element) || re.test(value);
          },
          \"Please check your input.\"
  );
  // validate signup form on keyup and submit
  $(\"#edit-form\").validate({
    rules: {
      password: {
        equalTo: \"#repassword\"
      },
      repassword: {
        equalTo: \"#password\"
      }
    },
    messages: {
      username: {
        required: 'กรุณากรอก Username',
        minlength: 'อย่างน้อย 4 ตัวอักษร',
        regex: 'ใช้ได้เฉพาะ a-z A-Z และ 0-9 เท่านั้น',
        remote: jQuery.validator.format('ชื่อนี้ได้ถูกใช้แล้ว โปรดลองใหม่')
      },
      firstname: 'โปรดกรอกชื่อจริง',
      lastname: 'โปรดกรอกนามสกุล',
      email: {
        required: 'กรุณากรอก Email',
        email: 'โปรดกรอกอีเมลล์ให้ถูกต้อง',
        remote: jQuery.validator.format('อีเมลล์นี้ได้ถูกใช้แล้ว โปรดลองใหม่')
      },
      password: {
        equalTo: 'รหัสผ่านจะต้องเหมือนกัน',
        rangelength: jQuery.format('อย่างน้อย {0} ตัวอักษร')
      },
      repassword: {
        minlength: jQuery.format('อย่างน้อย {0} ตัวอักษร'),
        equalTo: 'รหัสผ่านจะต้องเหมือนกัน'
      },
      phone: {
        required: 'กรุณากรอกเบอร์โทรศัพท์สำหรับติดต่อ'
      },
      address: {
        required: 'กรุณากรอกที่อยู่สำหรับติดต่อ'
      },
      district: {
        required: 'กรุณากรอกอำเภอ'
      },
      province: {
        required: 'กรุณาเลือกจังหวัด'
      },
      zipcode: {
        required: 'กรุณากรอกรหัสไปรษณีย์'
      }
    }
  });
});
</script>");
?>